- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·107 lines (85 loc) · 2.42 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<chrono>
#include"SortingAlgorithms.h"
usingnamespacestd;
usingnamespacestd::chrono ;
intmain(int argc, char** argv)
{
int numberElements;
int numberInput;
//Checking the input
if(argc != 2)
{
cout << "\n\n\t *** ERROR! *** \n" << endl;
cout << "\t" << argv[0] << " <method_number> < <input_file_name>" << endl;
cout << "\t -> Menu - sorting methods:\n"
"\t 1- Selection sort \n"
"\t 2- Insertion sort \n"
"\t 3- merge\n"
"\t 4- quick\n"
"\t 5- heap\n";
return -1;
}
std::cin >> numberElements;
//std::vector<int> vElements(numberElements) ;
std::vector<int> vElements;
vElements.reserve(numberElements);
for (int i = 0; i < numberElements; ++i)
{
std::cin >> numberInput;
vElements.push_back(numberInput);
}
//Creating the object the class SortingAlgorithms
SortingAlgorithms *sortingAlgorithms = newSortingAlgorithms();
auto start = steady_clock::now() ;
//Checking the input - Associating the number with thesorting methods:
switch ( atoi(argv[1]) )
{
case1:
sortingAlgorithms->selectionSort(vElements);
cout << "\t*** 1- Selection sort ***" << endl;
/*for(size_t i = 0; i < vElements.size(); i++)
{
std::cout << vElements[i] << std::endl;
}*/
break;
case2:
sortingAlgorithms->insertSort(vElements);
cout << "\t*** 2- Insertion sort ***" << endl;
/*for(size_t i = 0; i < vElements.size(); i++)
{
std::cout << vElements[i] << std::endl;
}*/
break;
case3:
sortingAlgorithms->mergeSort(0, vElements.size(), vElements);
cout << "\t*** 3- merge ***" << endl;
/*for(size_t i = 0; i < vElements.size(); i++)
{
std::cout << vElements[i] << std::endl;
}*/
break;
case4:
sortingAlgorithms->quickSort(0, vElements.size() - 1, vElements);
cout << "\t*** 4- quick ***" << endl;
/*for(size_t i = 0; i < vElements.size(); i++)
{
std::cout << vElements[i] << std::endl;
}*/
break;
case5:
sortingAlgorithms->heapSort(vElements);
cout << "\t*** 5- heap ***" << endl;
/*for(size_t i = 0; i < vElements.size(); i++)
{
std::cout << vElements[i] << std::endl;
}*/
break;
}
auto end = steady_clock::now() ;
std::cout << "\t that took " << duration_cast<milliseconds>(end-start).count()
<< " milliseconds\n" ;
return0;
}